package com.psfd.demo.controller;

import com.psfd.demo.bean.ProductType;
import com.psfd.demo.service.ProductTypeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@RestController
public class ProductTypeController {

    @Resource
    private ProductTypeService productTypeService;

    @RequestMapping("/protypeinsert")
    public ModelAndView insert(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("protypeadd");
        return modelAndView;
    }


    @RequestMapping("/insertProtype")
    public ModelAndView add(ProductType productType){
        System.err.println(productType+"1111111111111");
        productTypeService.save(productType);
        return queryAll();
    }




    @RequestMapping("/protypeupdate")
    public ModelAndView protypeupdate(Integer protypeid){
        System.out.println(protypeid);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("protypeid",protypeid);
        modelAndView.setViewName("protypeupdate");
        return modelAndView;
    }

    @RequestMapping("/updateProtype")
    public ModelAndView updateProtype(ProductType productType){
        System.err.println(productType+"--------------------");
        productTypeService.updateById(productType);
        return queryAll();
    }

    @RequestMapping("/deleteProtype")
    public ModelAndView delete(Integer protypeid){
        System.err.println(protypeid+"....................");
        productTypeService.removeById(protypeid);
        return queryAll();
    }


    @RequestMapping("/protypeQueryAll")
    public ModelAndView queryAll(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("protypelist",productTypeService.list());
        modelAndView.setViewName("protypeList");
        return modelAndView;
    }


//    @RequestMapping("/protypereturnpage")
//    public ModelAndView returnpage(){
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.setViewName("homepage");
//        return modelAndView;
//    }
}
